package jiyun.com.yiyanmeng;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import adapter.FragmentAdaper;
import base.BaseFragment;
import presenter.ShoppingPresenter;
import view.ShoppingView;


/**
 * A simple {@link Fragment} subclass.
 */
public class ShoppingFragment extends BaseFragment<ShoppingView, ShoppingPresenter> implements ShoppingView{

    private View view;
    private TabLayout mShopTab;
    private ViewPager mShopVp;
    private ArrayList<Fragment> list;
    private AllFragment allFragment;
    private BooksFragment booksFragment;
    private VideoFragment videoFragment;
    private FragmentAdaper adaper;

    public static ShoppingFragment newInstance() {

        Bundle args = new Bundle();

        ShoppingFragment fragment = new ShoppingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void showToast(String msg) {

    }

    @Override
    protected ShoppingPresenter bindPresenter() {
        return new ShoppingPresenter();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initView(View view) {
        mShopTab = (TabLayout) view.findViewById(R.id.shop_tab);
        mShopVp = (ViewPager) view.findViewById(R.id.shop_vp);
        list = new ArrayList<>();
        allFragment = new AllFragment();
        booksFragment = new BooksFragment();
        videoFragment = new VideoFragment();
        list.add(allFragment);
        list.add(booksFragment);
        list.add(videoFragment);
        adaper = new FragmentAdaper(getFragmentManager(), list);
        mShopVp.setAdapter(adaper);
        mShopTab.setupWithViewPager(mShopVp);
        mShopTab.getTabAt(0).setText("全部");
        mShopTab.getTabAt(1).setText("图书");
        mShopTab.getTabAt(2).setText("课程");
    }

    @Override
    protected int bindLayout() {
        return R.layout.fragment_shopping;
    }
}
